let power x n= if n<=0 then invalid_arg "n negatif ou nul"
  else let rec f n= (match n with 
      0->1
    |_ -> x*(f (n-1))) in f n;;

power 5 2;;


let rec application l x= match l with
               []->0
              |(a,n)::l-> a*(power x n)+ application l x;;
application [(2,2);(2,3);(4,4)] 2;;

let rec add l1 l2= match (l1,l2) with
                   (l1,[])->l1
                  |([],l2)->l2
  |((a,n1)::l1,(b,n2)::l2)-> if n1=n2 then (a+b,n1)::add l1 l2
                               else if n1<n2 then (a,n1)::add l1 ((b,n2)::l2)
                                     else (b,n2)::add ((a,n1)::l1) l2;;
add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

let rec soustract l1 l2 = match (l1,l2) with
                   (l1,[])->l1
                  |([],l2)->l2
  |((a,n1)::l1,(b,n2)::l2)-> if n1=n2 then let c=a-b in if c<>0 then (c,n1)::soustract l1 l2
                                                          else soustract l1 l2
                               else if n1<n2 then (a,n1)::soustract l1 ((b,n2)::l2)
                                   else (0-b,n2)::soustract ((a,n1)::l1) l2;;
soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

let rec deriv l = match l with
            []->[]
           |(a,n)::l-> (a*n,n-1)::deriv l;;  

